# -*- coding: utf-8 -*-            
# @Time : 2023/8/23 9:37
# @FileName: translate_test.py
# @Target:
import json, codecs, time, os
from pprint import pprint
import pandas as pd


import codecs
import json

import requests

res = requests.get(
    url='http://123.58.213.162:17400/csp_labels_convert',
)

pprint(json.loads(res.content.decode()))

#
# import requests
# import time
# import os
# # from utils.mongo import logger
# HOST = os.getenv('host', '152.32.135.145')
#
# class Translator:
#     def __init__(self):
#         self.url = "http://{host}:17310/translate".format(
#             host=HOST
#         )
#         self.fa = {}
#     def translate(self, sentence):
#         if sentence=='':
#             return ''
#         if sentence in self.fa.keys():
#             return self.fa[sentence]
#         data = {
#             'sentence': sentence,
#         }
#         res = requests.post(
#             url=self.url, data=data
#         )
#         result = json.loads(res.content.decode('unicode_escape'))['trans_result']
#         # logger.insert_translation(result)
#         self.fa.update({sentence : result[0]['dst']})
#         return result[0]['dst']
# translator = Translator()
#
#
# # TODO : 整理Excel表格中的CSP标签数据
# df = pd.read_excel("labels.xlsx", sheet_name='CSP')
# DICT = {}
# for row_index, row in df.iterrows():
#     idmi_Level1 = row['idmi_Level1']
#     idmi_Level2 = row['idmi_Level2']
#     idmi_Level3 = row['idmi_Level3']
#     csp_Level1 = row['csp_Level1'] if isinstance(row['csp_Level1'], str) else ''
#     csp_Level2 = row['csp_Level2'] if isinstance(row['csp_Level2'], str) else ''
#     csp_Level3 = row['csp_Level3'] if isinstance(row['csp_Level3'], str) else ''
#     csp_Level4 = row['csp_Level4'] if isinstance(row['csp_Level4'], str) else ''
#
# # 先整理如何Prompt的字典
#     if idmi_Level1 not in DICT.keys():
#         DICT.update({ idmi_Level1: {} })
#     if idmi_Level2 not in DICT[idmi_Level1].keys():
#         DICT[idmi_Level1].update({ idmi_Level2: [[], [], []]})
#     if isinstance(idmi_Level3, str):
#         if idmi_Level3 not in DICT[idmi_Level1][idmi_Level2]:
#             DICT[idmi_Level1][idmi_Level2][0].append( idmi_Level3 )
#             DICT[idmi_Level1][idmi_Level2][1].append( {
#                 'csp_1': csp_Level1,
#                 'csp_2':csp_Level2,
#                 'csp_3':csp_Level3,
#                 'csp_4':csp_Level4
#             } )
#             DICT[idmi_Level1][idmi_Level2][2].append( {
#                 'csp_1': translator.translate(csp_Level1),
#                 'csp_2':translator.translate(csp_Level2),
#                 'csp_3':translator.translate(csp_Level3),
#                 'csp_4':translator.translate(csp_Level4)
#             } )
#     else:
#         DICT[idmi_Level1][idmi_Level2][1].append({
#             'csp_1': csp_Level1,
#             'csp_2': csp_Level2,
#             'csp_3': csp_Level3,
#             'csp_4': csp_Level4
#         })
#         DICT[idmi_Level1][idmi_Level2][2].append({
#             'csp_1': translator.translate(csp_Level1),
#             'csp_2': translator.translate(csp_Level2),
#             'csp_3': translator.translate(csp_Level3),
#             'csp_4': translator.translate(csp_Level4)
#         })
#
# with codecs.open(filename='labels/csp_label.json', mode='w', encoding='utf-8') as fw:
#     json.dump(obj=DICT, fp=fw, ensure_ascii=False, indent=4)
#
#
#
#
#
#
#
#
#
#
#


